//===--- Passes.def - Swift SILPass Metaprogramming -------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file defines macros used for macro-metaprogramming with SILPasses.
//
//===----------------------------------------------------------------------===//

/// PASS(Id, Name, Description)
///   The pass is identified by PassKind::Id, and there exists a
///   global function swift::create##Id().
///
///   This macro must be defined by the includer.
#ifndef PASS
#error "Macro must be defined by includer"
#endif

/// PASS_RANGE(RANGE_ID, START, END)
///   Pass IDs between PassKind::START and PassKind::END, inclusive,
///   fall within the set known as 
#ifndef PASS_RANGE
#define PASS_RANGE(Id, First, Last)
#endif

PASS(AADumper, "aa-dump",
     "Dump AA result for all pairs of ValueKinds in all functions")
PASS(ABCOpt, "abcopts",
     "Optimization of array bounds checks")
PASS(AllocBoxToStack, "allocbox-to-stack",
     "Promote heap allocations to stack allocations")
PASS(ArrayCountPropagation, "array-count-propagation",
     "Propagate the count of arrays")
PASS(BasicCalleePrinter, "basic-callee-printer",
     "Construct basic callee analysis and use it to print callees "
     "for testing purposes")
PASS(CFGPrinter, "view-cfg",
     "View the CFG of all passed in functions")
PASS(COWArrayOpts, "cowarray-opt",
     "COW Array optimizations")
PASS(CSE, "cse",
     "Common subexpression elimination")
PASS(CallGraphPrinter, "call-graph-printer",
     "Construct and print the call graph for use in testing")
PASS(CapturePromotion, "capture-promotion",
     "Promote captures from by-reference to by-value")
PASS(CapturePropagation, "capture-prop",
     "Captured Constant Propagation")
PASS(ClosureSpecializer, "closure-specialize",
     "Specialize functions passed a closure to call the closure directly")
PASS(CodeSinking, "code-sinking",
     "Sinks code closer to users")
PASS(CopyForwarding, "copy-forwarding",
     "Eliminate redundant copies")
PASS(RedundantOverflowCheckRemoval, "remove-redundant-overflow-checks",
     "Removes redundant overflow checks")
PASS(DCE, "dce",
     "Eliminate dead code")
PASS(DeadFunctionElimination, "sil-deadfuncelim",
     "Remove unused functions")
PASS(DeadObjectElimination, "deadobject-elim",
     "Eliminate unused objects that do not have destructors with side effects")
PASS(DefiniteInitialization, "definite-init",
     "Definite Initialization")
PASS(DiagnoseUnreachable, "diagnose-unreachable",
     "Diagnose Unreachable Code")
PASS(DiagnosticConstantPropagation, "diagnostic-constant-propagation",
     "Propagate constants and emit diagnostics")
PASS(EarlyCodeMotion, "early-codemotion",
     "Code motion without release hoisting")
PASS(EarlyInliner, "early-inline",
     "Inline functions that are not marked as having special semantics")
PASS(EmitDFDiagnostics, "dataflow-diagnostics",
     "Emit SIL Diagnostics")
PASS(ExternalDefsToDecls, "external-defs-to-decls",
     "Convert external definitions to decls")
PASS(ExternalFunctionDefinitionsElimination, "external-func-definition-elim",
     "Eliminate external function definitions")
PASS(FunctionOrderPrinter, "function-order-printer",
     "Print function orderings for test purposes")
PASS(FunctionSignatureOpts, "function-signature-opts",
     "Optimize Function Signatures")
PASS(ARCSequenceOpts, "arc-sequence-opts",
     "Optimize sequences of retain/release opts by removing redundant inner "
     "retain/release sequenes")
PASS(RedundantLoadElimination, "redundant-load-elim",
     "Multiple basic block redundant load elimination")
PASS(DeadStoreElimination, "dead-store-elim",
     "Multiple basic block dead store elimination")
PASS(GlobalOpt, "global-opt",
     "Global variable optimizations")
PASS(GlobalPropertyOpt, "global-property-opt",
     "Optimize properties")
PASS(HighLevelCSE, "high-level-cse",
     "Common subexpression elimination on High-level SIL")
PASS(HighLevelLICM, "high-level-licm",
     "High Level Loop invariant code motion")
PASS(IVInfoPrinter, "iv-info-printer",
     "Display induction variable information")
PASS(InOutDeshadowing, "inout-deshadow",
     "Remove inout argument shadow variables")
PASS(InstCount, "inst-count",
     "Count all instructions in the module using llvm Statistics")
PASS(JumpThreadSimplifyCFG, "simplify-cfg",
     "Clean up the CFG of SIL functions")
PASS(LetPropertiesOpt, "let-properties-opt",
     "SIL let properties optimization")
PASS(LICM, "licm",
     "Loop invariant code motion")
PASS(LateCodeMotion, "late-codemotion",
     "Code motion with release hoisting")
PASS(LateInliner, "late-inline",
     "Run the late inliner")
PASS(LoopCanonicalizer, "loop-canonicalizer",
     "Canonicalize loops")
PASS(LoopInfoPrinter, "loop-info-printer",
     "Display loop information")
PASS(LoopRegionViewText, "loop-region-view-text",
     "Construct the loop region data structure and dump its contents as text")
PASS(LoopRegionViewCFG, "loop-region-view-cfg",
     "Construct the loop region data structure and dump its contents as a pdf cfg")
PASS(LoopRotate, "loop-rotate",
     "Rotate loops")
PASS(LowerAggregateInstrs, "lower-aggregate-instrs",
     "Lower aggregate instructions to scalar instructions")
PASS(MandatoryInlining, "mandatory-inlining",
     "Inline transparent functions")
PASS(Mem2Reg, "mem2reg",
     "Promote stack allocations to SSA values")
PASS(MemBehaviorDumper, "mem-behavior-dump",
     "Dump MemBehavior results from alias analysis for all instruction pairs")
PASS(MemLocationPrinter, "memlocation-dump",
     "Dump MemLocation results from analyzing all accessed locations")
PASS(MergeCondFails, "merge-cond_fails",
     "Remove redundant overflow checks")
PASS(NoReturnFolding, "noreturn-folding",
     "Add 'unreachable' after noreturn calls")
// TODO: It makes no sense to have early inliner, late inliner, and
// perf inliner in terms of names.
PASS(PerfInliner, "inline",
     "Inline functions which are determined to be less than a pre-set cost")
PASS(PerformanceConstantPropagation, "performance-constant-propagation",
     "Propagate constants and do not emit diagnostics")
PASS(PredictableMemoryOptimizations, "predictable-memopt",
     "Predictable early memory optimizations")
PASS(ReleaseDevirtualizer, "release-devirtualizer",
     "Devirtualize release-instructions")
PASS(RemovePins, "remove-pins",
     "Remove pin/unpin pairs")
PASS(SILCleanup, "cleanup",
     "Cleanup SIL in preparation for IRGen")
PASS(SILCombine, "sil-combine",
     "Perform small peepholes and combine operations")
PASS(SILLinker, "linker",
     "Link in all of the serialized SIL referenced in the module")
PASS(SROA, "sroa",
     "SIL scalar replacement of aggregates")
PASS(SROABBArgs, "sroa-bb-args",
     "SIL scalar replacement of aggregates of bb arguments")
PASS(SimplifyBBArgs, "simplify-bb-args",
     "Simplify basic block arguments")
// TODO: What should this be called. We are just following what was previously in SILOpt.
PASS(SimplifyCFG, "normal-simplify-cfg",
     "Clean up the CFG of SIL functions")
PASS(SpeculativeDevirtualization, "specdevirt",
     "Speculate targets of virtual calls")
PASS(SplitAllCriticalEdges, "split-critical-edges",
     "Split all critical edges")
PASS(SplitNonCondBrCriticalEdges, "split-non-cond_br-critical-edges",
     "Split all critical edges that do not involve cond_br")
PASS(StackPromotion, "stack-promotion",
     "Promote allocated objects on the stack")
PASS(StripDebugInfo, "strip-debug-info",
     "Strip debug info")
PASS(SwiftArrayOpts, "array-specialize",
     "Specialize arrays")
PASS(UpdateEscapeAnalysis, "update-escapes",
     "Update the escape analysis for all functions")
PASS(UpdateSideEffects, "side-effects",
     "Update the side effect analysis for all functions")
PASS(UsePrespecialized, "use-prespecialized",
     "Use pre-specialized functions")
PASS_RANGE(AllPasses, AADumper, UsePrespecialized)

#undef PASS
#undef PASS_RANGE
